import $on from './_on.coffee'

export default (win)=>
  resolve = undefined
  p = new Promise (_resolve)=>
    resolve = _resolve
    return
  if document.hidden
    resolve()
  else
    unbind = $on document,{
      visibilitychange:=>
        if document.hidden
          unbind()
          setTimeout(
            resolve
            100
          )
        return
    }
  win.hide()

  p
